package com.example.speeddating.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.speeddating.entity.Topic;
import com.example.speeddating.mapper.TopicMapper;
import com.example.speeddating.service.TopicService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * @author tina
 * @since 2023-06-28 11:14:34
 */
@Service
public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements TopicService {

    @Autowired
    private TopicMapper topicMapper;

    @Override
    public List<Topic> getHotTopics() {
        return topicMapper.getHotTopics();
    }

    @Override
    public Page<Topic> getAllTopics(Page<Topic> topicPage,String searchData) {
        return topicMapper.getAllTopics(topicPage,searchData);
    }

    @Override
    public Page<Topic> getUserJoinedTopic(Page<Topic> topicPage, Long userId) {
        return topicMapper.getUserJoinedTopic(topicPage, userId);
    }

    @Override
    public Topic getTopicById(Integer topicId) {
        return topicMapper.selectById(topicId);
    }

    @Override
    public void incrementJoinedNum(Integer topicId) {
        Topic topic = getTopicById(topicId);
        topic.setJoinNum(topic.getJoinNum()+1);
        topicMapper.updateById(topic);
    }

    @Override
    public void decrementJoinedNum(Integer topicId) {
        Topic topic = getTopicById(topicId);
        topic.setJoinNum(topic.getJoinNum()-1);
        topicMapper.updateById(topic);
    }

    @Override
    public void incrementTopicTot(Integer topicId,Integer num) {
        Topic topic = getTopicById(topicId);
        topic.setHot(topic.getHot()+num);
        topicMapper.updateById(topic);
    }



    @Override
    public Page<Topic> selectAllTopic(Page<Topic> pageInfo) {
        return topicMapper.selectAllTopic(pageInfo);
    }
}
